use std::time::Duration;

use serde::{Deserialize, Serialize};
use talktive::{TalkTive, TalktiveKenerlConfig};

use crate::ChatGLMRemote;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatGLMRemoteConfig {
    pub addr: String,
    pub app_key: String,
    ///有效时间
    pub exp_dur: Duration,
    pub gen_config: GenerateConfig,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerateConfig {
    pub temperature: Option<f32>,
    pub top_p: Option<f32>,
    pub seed: Option<i32>,
    pub max_tokens: Option<i32>,
    pub do_sample: Option<bool>,
}

impl Default for ChatGLMRemoteConfig {
    fn default() -> Self {
        Self {
            addr: "https://open.bigmodel.cn/api/paas/v4/chat/completions".into(),
            app_key: "".into(),
            exp_dur: Duration::from_secs(180),
            gen_config: Default::default(),
        }
    }
}

impl Default for GenerateConfig {
    fn default() -> Self {
        Self {
            temperature: None,
            top_p: None,
            seed: None,
            max_tokens: None,
            do_sample: Some(true),
        }
    }
}

impl TalktiveKenerlConfig for ChatGLMRemoteConfig {
    type Kenerl = ChatGLMRemote;
}
